//
//  ByCellBindOtherApp.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/20.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellBindOtherApp.h"

@implementation ByCellBindOtherApp
{
    CAShapeLayer *_dottedLayer;
    
    UIImageView *_wechatIconView;
    UILabel     *_wechatBindStatusView;
    UIImageView *_alipayIconView;
    UILabel     *_alipayBindStatusView;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    // 虚线
    _dottedLayer = [CAShapeLayer layer];
    _dottedLayer.lineDashPattern = @[@3, @2];
    _dottedLayer.lineWidth = 1;
    _dottedLayer.strokeColor = [UIColor colorWithWhite:0.8 alpha:1].CGColor;
    [self.contentView.layer addSublayer:_dottedLayer];
    
    // 微信
    _wechatIconView = [UIImageView new];
    _wechatIconView.image = [UIImage imageNamed:@"微信"];
    [self.contentView addSubview:_wechatIconView];
    [_wechatIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.centerX.equalTo(self.contentView).multipliedBy(0.5);
        make.top.equalTo(self).offset(15);
    }];
    _wechatBindStatusView = [[UILabel alloc] init];
    _wechatBindStatusView.adjustsFontSizeToFitWidth = true;
    _wechatBindStatusView.numberOfLines = 1;
    _wechatBindStatusView.text = @"text";
    _wechatBindStatusView.font = FONT(14);
    _wechatBindStatusView.textAlignment = NSTextAlignmentCenter;
    _wechatBindStatusView.textColor = [UIColor blackColor];
    [self addSubview:_wechatBindStatusView];
    [_wechatBindStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_wechatIconView.mas_bottom).offset(5);
        make.height.equalTo(@20);
        make.width.equalTo(self).multipliedBy(0.5);
        make.centerX.equalTo(_wechatIconView);
    }];
    
    // 支付宝
    _alipayIconView = [UIImageView new];
    _alipayIconView.image = [UIImage imageNamed:@"支付宝"];
    [self.contentView addSubview:_alipayIconView];
    [_alipayIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(_wechatIconView);
        make.centerX.equalTo(self.contentView).multipliedBy(1.5);
        make.top.equalTo(_wechatIconView);
    }];
    _alipayBindStatusView = [[UILabel alloc] init];
    _alipayBindStatusView.adjustsFontSizeToFitWidth = true;
    _alipayBindStatusView.numberOfLines = 1;
    _alipayBindStatusView.text = @"text";
    _alipayBindStatusView.font = FONT(14);
    _alipayBindStatusView.textAlignment = NSTextAlignmentCenter;
    _alipayBindStatusView.textColor = [UIColor blackColor];
    [self addSubview:_alipayBindStatusView];
    [_alipayBindStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_wechatBindStatusView);
        make.height.equalTo(_wechatBindStatusView);
        make.width.equalTo(_wechatBindStatusView);
        make.centerX.equalTo(_alipayIconView);
    }];
}

- (void)layoutSubviews {
    
    UIBezierPath *dottedPath = [UIBezierPath bezierPath];
    [dottedPath moveToPoint:CGPointMake(self.width / 2, 10)];
    [dottedPath addLineToPoint:CGPointMake(self.width / 2, self.height - 10)];
    _dottedLayer.path = dottedPath.CGPath;
}

- (void)setBindStatus:(NSArray *)bindStatus {
    
    _bindStatus = bindStatus;
    
    BOOL wechatBind = [bindStatus[0] boolValue];
    BOOL alipayBind = [bindStatus[1] boolValue];
    
    _wechatBindStatusView.textColor = wechatBind ? [UIColor blackColor] : [UIColor lightGrayColor];
    _alipayBindStatusView.textColor = alipayBind ? [UIColor blackColor] : [UIColor lightGrayColor];
    
    _wechatBindStatusView.text = wechatBind ? @"已绑定微信" : @"未绑定微信";
    _alipayBindStatusView.text = alipayBind ? @"已绑定支付宝" : @"未绑定支付宝";
}
@end
